3 * Contain the EditPage class
8 * Splitting edit page/HTML interface from Article...
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
22 var $save = false, $preview = false, $diff = false;
23 var $minoredit = false, $watchthis = false;
24 var $textbox1 = '', $textbox2 = '', $summary = '';
25 var $edittime = '', $section = '';
32 function EditPage( $article ) {
33 $this->mArticle
=& $article;
35 $this->mTitle
=& $wgTitle;
39 * This is the function that extracts metadata from the article body on the first view.
40 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
41 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
43 function extractMetaDataFromArticle ()
45 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
46 $this->mMetaData
= '' ;
47 if ( !$wgUseMetadataEdit ) return ;
48 if ( $wgMetadataWhitelist == "" ) return ;
50 $t = $this->mArticle
->getContent ( true ) ;
52 # MISSING : <nowiki> filtering
54 # Categories and language links
55 $t = explode ( "\n" , $t ) ;
56 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
57 $cat = $ll = array() ;
58 foreach ( $t AS $key => $x )
60 $y = trim ( strtolower ( $x ) ) ;
61 while ( substr ( $y , 0 , 2 ) == "[[" )
63 $y = explode ( "]]" , trim ( $x ) ) ;
64 $first = array_shift ( $y ) ;
65 $first = explode ( ":" , $first ) ;
66 $ns = array_shift ( $first ) ;
67 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
68 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
70 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
71 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
73 $x = implode ( ']]' , $y ) ;
75 $y = trim ( strtolower ( $x ) ) ;
79 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
80 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
81 $t = implode ( "\n" , $t ) ;
84 $sat = array () ; # stand-alone-templates; must be lowercase
85 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
86 $wl_article = new Article ( $wl_title ) ;
87 $wl = explode ( "\n" , $wl_article->getContent(true) ) ;
92 while ( substr ( $x , 0 , 1 ) == '*' )
95 $x = trim ( substr ( $x , 1 ) ) ;
99 $sat[] = strtolower ( $x ) ;
104 # Templates, but only some
105 $t = explode ( '{{' , $t ) ;
107 foreach ( $t AS $key => $x )
109 $y = explode ( '}}' , $x , 2 ) ;
110 if ( count ( $y ) == 2 )
113 $z = explode ( '|' , $z ) ;
114 $tn = array_shift ( $z ) ;
115 if ( in_array ( strtolower ( $tn ) , $sat ) )
117 $tl[] = '{{' . $y[0] . '}}' ;
119 $y = explode ( '}}' , $y[1] , 2 ) ;
121 else $t[$key] = '{{' . $x ;
123 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
126 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
127 $t = implode ( '' , $t ) ;
129 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
130 $this->mArticle
->mContent
= $t ;
131 $this->mMetaData
= $s ;
135 * This is the function that gets called for "action=edit".
138 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
139 // this is not an article
140 $wgOut->setArticleFlag(false);
142 $this->importFormData( $wgRequest );
145 $this->livePreview();
149 if ( ! $this->mTitle
->userCanEdit() ) {
150 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
153 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlocked( !$this->save
) ) {
154 # When previewing, don't check blocked state - will get caught at save time.
155 # Also, check when starting edition is done against slave to improve performance.
156 $this->blockedIPpage();
159 if ( $wgUser->isAnon() && $wgWhitelistEdit ) {
160 $this->userNotLoggedInPage();
163 if ( wfReadOnly() ) {
164 if( $this->save ||
$this->preview
) {
165 $this->editForm( 'preview' );
166 } else if ( $this->diff
) {
167 $this->editForm( 'diff' );
169 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
174 $this->editForm( 'save' );
175 } else if ( $this->preview
) {
176 $this->editForm( 'preview' );
177 } else if ( $this->diff
) {
178 $this->editForm( 'diff' );
179 } else { # First time through
180 if( $wgUser->getOption('previewonfirst') ) {
181 $this->editForm( 'preview', true );
183 $this->extractMetaDataFromArticle () ;
184 $this->editForm( 'initial', true );
192 function importFormData( &$request ) {
193 if( $request->wasPosted() ) {
194 # These fields need to be checked for encoding.
195 # Also remove trailing whitespace, but don't remove _initial_
196 # whitespace from the text boxes. This may be significant formatting.
197 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
198 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
199 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
200 $this->summary
= trim( $request->getText( 'wpSummary' ) );
202 $this->edittime
= $request->getVal( 'wpEdittime' );
203 if( is_null( $this->edittime
) ) {
204 # If the form is incomplete, force to preview.
205 $this->preview
= true;
207 if( $this->tokenOk( $request ) ) {
208 # Some browsers will not report any submit button
209 # if the user hits enter in the comment box.
210 # The unmarked state will be assumed to be a save,
211 # if the form seems otherwise complete.
212 $this->preview
= $request->getCheck( 'wpPreview' );
213 $this->diff
= $request->getCheck( 'wpDiff' );
215 # Page might be a hack attempt posted from
216 # an external site. Preview instead of saving.
217 $this->preview
= true;
220 $this->save
= ! ( $this->preview
OR $this->diff
);
221 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
222 $this->edittime
= null;
225 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
226 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
228 # Not a posted form? Start with nothing.
229 $this->textbox1
= '';
230 $this->textbox2
= '';
231 $this->mMetaData
= '';
233 $this->edittime
= '';
234 $this->preview
= false;
237 $this->minoredit
= false;
238 $this->watchthis
= false;
241 $this->oldid
= $request->getInt( 'oldid' );
243 # Section edit can come from either the form or a link
244 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
246 $this->live
= $request->getCheck( 'live' );
250 * Make sure the form isn't faking a user's credentials.
252 * @param WebRequest $request
256 function tokenOk( &$request ) {
258 if( $wgUser->isAnon() ) {
259 # Anonymous users may not have a session
260 # open. Don't tokenize.
263 return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
272 * The edit form is self-submitting, so that when things like
273 * preview and edit conflicts occur, we get the same form back
274 * with the extra stuff added. Only when the final submission
275 * is made and all is well do we actually save and redirect to
276 * the newly-edited page.
278 * @param string $formtype Type of form either : save, initial, diff or preview
279 * @param bool $firsttime True to load form data from db
281 function editForm( $formtype, $firsttime = false ) {
282 global $wgOut, $wgUser;
283 global $wgLang, $wgContLang, $wgParser, $wgTitle;
284 global $wgAllowAnonymousMinor;
285 global $wgWhitelistEdit;
286 global $wgSpamRegex, $wgFilterCallback;
288 $sk = $wgUser->getSkin();
290 // css / js subpages of user pages get a special treatment
291 $isCssJsSubpage = $wgTitle->isCssJsSubpage();
294 if(!$this->mTitle
->getArticleID()) { # new article
295 $wgOut->addWikiText(wfmsg('newarticletext'));
298 if( $this->mTitle
->isTalkPage() ) {
299 $wgOut->addWikiText(wfmsg('talkpagetext'));
302 # Attempt submission here. This will check for edit conflicts,
303 # and redundantly check for locked database, blocked IPs, etc.
304 # that edit() already checked just in case someone tries to sneak
305 # in the back door with a hand-edited submission URL.
307 if ( 'save' == $formtype ) {
308 # Reintegrate metadata
309 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
310 $this->mMetaData
= '' ;
313 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
314 $this->spamPage ( $matches[0] );
317 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
318 # Error messages or other handling should be performed by the filter function
321 if ( $wgUser->isBlocked( false ) ) {
322 # Check block state against master, thus 'false'.
323 $this->blockedIPpage();
326 if ( $wgUser->isAnon() && $wgWhitelistEdit ) {
327 $this->userNotLoggedInPage();
330 if ( wfReadOnly() ) {
331 $wgOut->readOnlyPage();
335 # If article is new, insert it.
336 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
338 # Don't save a new article if it's blank.
339 if ( ( '' == $this->textbox1
) ||
340 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
341 $wgOut->redirect( $this->mTitle
->getFullURL() );
344 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$this->textbox1
,
345 &$this->summary
, &$this->minoredit
, &$this->watchthis
, NULL)))
347 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
348 $this->minoredit
, $this->watchthis
);
349 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $this->textbox1
,
350 $this->summary
, $this->minoredit
,
351 $this->watchthis
, NULL));
356 # Article exists. Check for edit conflict.
358 $this->mArticle
->clear(); # Force reload of dates, etc.
359 $this->mArticle
->forUpdate( true ); # Lock the article
361 if( ( $this->section
!= 'new' ) &&
362 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
365 $userid = $wgUser->getID();
368 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime'\n" );
369 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
370 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
373 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
374 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
375 $this->section
, $this->textbox1
, $this->summary
);
377 # Suppress edit conflict with self
379 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
382 # switch from section editing to normal editing in edit conflict
385 if( $this->mergeChangesInto( $text ) ){
386 // Successful merge! Maybe we should tell the user the good news?
390 $this->textbox1
= $text;
394 if ( ! $isConflict ) {
397 if( $this->section
== 'new' ) {
398 if( $this->summary
!= '' ) {
399 $sectionanchor = $this->sectionAnchor( $this->summary
);
401 } elseif( $this->section
!= '' ) {
402 # Try to get a section anchor from the section source, redirect to edited section if header found
403 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
404 # for duplicate heading checking and maybe parsing
405 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
406 # we can't deal with anchors, includes, html etc in the header for now,
407 # headline would need to be parsed to improve this
408 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
409 if($hasmatch and strlen($matches[2]) > 0) {
410 $sectionanchor = $this->sectionAnchor( $matches[2] );
414 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$text,
415 &$this->summary
, &$this->minoredit
,
416 &$this->watchthis
, &$sectionanchor)))
418 # update the article here
419 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
420 $this->watchthis
, '', $sectionanchor ))
422 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $text,
423 $this->summary
, $this->minoredit
,
424 $this->watchthis
, $sectionanchor));
432 # First time through: get contents, set time for conflict
435 if ( 'initial' == $formtype ||
$firsttime ) {
436 $this->edittime
= $this->mArticle
->getTimestamp();
437 $this->textbox1
= $this->mArticle
->getContent( true );
441 $wgOut->setRobotpolicy( 'noindex,nofollow' );
443 # Enabled article-related sidebar, toplinks, etc.
444 $wgOut->setArticleRelated( true );
446 # Calculate preview html - must be here, because for the next things you
447 # have to know, if the title changes because of __LCFIRST__
448 if ( 'preview' == $formtype) {
449 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
453 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
454 $wgOut->setPageTitle( $s );
455 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
457 $this->textbox2
= $this->textbox1
;
458 $this->textbox1
= $this->mArticle
->getContent( true );
459 $this->edittime
= $this->mArticle
->getTimestamp();
462 if( $this->section
!= '' ) {
463 if( $this->section
== 'new' ) {
464 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
466 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
468 if(!$this->preview
) {
469 preg_match( "/^(=+)(.+)\\1/mi",
472 if( !empty( $matches[2] ) ) {
473 $this->summary
= "/* ". trim($matches[2])." */ ";
477 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
479 $wgOut->setPageTitle( $s );
480 if ( !$this->checkUnicodeCompliantBrowser() ) {
481 $this->mArticle
->setOldSubtitle();
482 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
484 if ( $this->oldid
) {
485 $this->mArticle
->setOldSubtitle();
486 $wgOut->addWikiText( wfMsg( 'editingold' ) );
491 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
492 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
493 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
495 if( $this->mTitle
->isProtected('edit') ) {
496 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
499 $kblength = (int)(strlen( $this->textbox1
) / 1024);
500 if( $kblength > 29 ) {
501 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
504 $rows = $wgUser->getOption( 'rows' );
505 $cols = $wgUser->getOption( 'cols' );
507 $ew = $wgUser->getOption( 'editwidth' );
508 if ( $ew ) $ew = " style=\"width:100%\"";
511 $q = 'action=submit';
512 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
513 $action = $this->mTitle
->escapeLocalURL( $q );
515 $summary = wfMsg('summary');
516 $subject = wfMsg('subject');
517 $minor = wfMsg('minoredit');
518 $watchthis = wfMsg ('watchthis');
519 $save = wfMsg('savearticle');
520 $prev = wfMsg('showpreview');
521 $diff = wfMsg('showdiff');
523 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
525 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
526 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
527 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
528 htmlspecialchars( wfMsg( 'newwindow' ) );
530 global $wgRightsText;
531 $copywarn = "<div id=\"editpage-copywarn\">\n" .
532 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
533 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
534 $wgRightsText ) . "\n</div>";
536 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
537 # prepare toolbar for edit buttons
538 $toolbar = $this->getEditToolbar();
543 // activate checkboxes if user wants them to be always active
544 if( !$this->preview
&& !$this->diff
) {
545 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
546 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
548 // activate checkbox also if user is already watching the page,
549 // require wpWatchthis to be unset so that second condition is not
550 // checked unnecessarily
551 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
556 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
558 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
559 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
560 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
565 if ( $wgUser->isLoggedIn() ) {
566 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
567 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
568 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
571 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
573 $wgOut->addHTML( '<div id="wikiPreview">' );
574 if ( 'preview' == $formtype) {
575 if ( $wgUser->getOption('previewontop' ) ) {
576 $wgOut->addHTML( $previewOutput );
577 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
580 $wgOut->addHTML( '</div>' );
581 if ( 'diff' == $formtype ) {
582 if ( $wgUser->getOption('previewontop' ) ) {
583 $wgOut->addHTML( $this->getDiff() );
588 # if this is a comment, show a subject line at the top, which is also the edit summary.
589 # Otherwise, show a summary field at the bottom
590 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
591 if( $this->section
== 'new' ) {
592 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
595 $commentsubject = '';
596 $editsummary="{$summary}: <input tabindex='2' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
599 if( !$this->preview
&& !$this->diff
) {
600 # Don't select the edit box on preview; this interferes with seeing what's going on.
601 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
603 # Prepare a list of templates used by this page
605 $articleTemplates = $this->mArticle
->getUsedTemplates();
606 if ( count( $articleTemplates ) > 0 ) {
607 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
608 foreach ( $articleTemplates as $tpl ) {
609 if ( $titleObj = Title
::makeTitle( NS_TEMPLATE
, $tpl ) ) {
610 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
613 $templates .= '</ul>';
616 global $wgLivePreview, $wgStylePath;
618 * Live Preview lets us fetch rendered preview page content and
619 * add it to the page without refreshing the whole page.
620 * Set up the button for it; if not supported by the browser
621 * it will fall through to the normal form submission method.
623 if( $wgLivePreview ) {
624 global $wgJsMimeType;
625 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
626 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
627 '"></script>' . "\n" );
628 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
629 $liveOnclick = 'onclick="return !livePreview('.
630 'getElementById(\'wikiPreview\'),' .
631 'editform.wpTextbox1.value,' .
632 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
637 global $wgUseMetadataEdit ;
638 if ( $wgUseMetadataEdit )
640 $metadata = $this->mMetaData
;
641 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
642 $helppage = Title
::newFromText ( wfmsg("metadata_page") ) ;
643 $top = str_replace ( "$1" , $helppage->getInternalURL() , wfmsg("metadata") ) ;
644 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
646 else $metadata = "" ;
649 $wgOut->addHTML( <<<END
651 <form id="editform" name="editform" method="post" action="$action"
652 enctype="multipart/form-data">
654 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
657 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
663 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
664 " title=\"".wfMsg('tooltip-save')."\"/>
665 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
666 " title=\"".wfMsg('tooltip-preview')."\"/>
667 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
668 " title=\"".wfMsg('tooltip-diff')."\"/>
669 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
670 $wgOut->addWikiText( $copywarn );
672 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
673 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
675 if ( $wgUser->isLoggedIn() ) {
677 * To make it harder for someone to slip a user a page
678 * which submits an edit form to the wiki without their
679 * knowledge, a random token is associated with the login
680 * session. If it's not passed back with the submission,
681 * we won't save the page, or render user JavaScript and
684 $token = htmlspecialchars( $wgUser->editToken() );
686 <input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
691 require_once( "DifferenceEngine.php" );
692 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
693 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
694 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
696 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
697 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
698 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
702 $wgOut->addHTML( "</form>\n" );
703 if ( $formtype == 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
704 $wgOut->addHTML( '<div id="wikiPreview">' . $previewOutput . '</div>' );
706 if ( $formtype == 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
707 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
708 $wgOut->addHTML( $this->getDiff() );
715 function getPreviewText( $isConflict, $isCssJsSubpage ) {
716 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
717 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
718 "<p class='previewnote'>" . htmlspecialchars( wfMsg( 'previewnote' ) ) . "</p>\n";
720 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) .
724 $parserOptions = ParserOptions
::newFromUser( $wgUser );
725 $parserOptions->setEditSection( false );
727 # don't parse user css/js, show message about preview
728 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
730 if ( $isCssJsSubpage ) {
731 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
732 $previewtext = wfMsg('usercsspreview');
733 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
734 $previewtext = wfMsg('userjspreview');
736 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
737 $wgOut->addHTML( $parserOutput->mText
);
740 # if user want to see preview when he edit an article
741 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
742 $this->textbox1
= $this->mArticle
->getContent(true);
745 $toparse = $this->textbox1
;
746 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
748 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
749 $wgTitle, $parserOptions );
751 $previewHTML = $parserOutput->mText
;
753 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
754 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
755 return $previewhead . $previewHTML;
762 function blockedIPpage() {
763 global $wgOut, $wgUser, $wgContLang, $wgIP;
765 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
766 $wgOut->setRobotpolicy( 'noindex,nofollow' );
767 $wgOut->setArticleRelated( false );
769 $id = $wgUser->blockedBy();
770 $reason = $wgUser->blockedFor();
773 if ( is_numeric( $id ) ) {
774 $name = User
::whoIs( $id );
778 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
779 ":{$name}|{$name}]]";
781 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
782 $wgOut->returnToMain( false );
788 function userNotLoggedInPage() {
791 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
792 $wgOut->setRobotpolicy( 'noindex,nofollow' );
793 $wgOut->setArticleRelated( false );
795 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
796 $wgOut->returnToMain( false );
802 function spamPage ( $match = false )
805 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
806 $wgOut->setRobotpolicy( 'noindex,nofollow' );
807 $wgOut->setArticleRelated( false );
809 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
811 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
813 $wgOut->returnToMain( false );
817 * Forks processes to scan the originating IP for an open proxy server
818 * MemCached can be used to skip IPs that have already been scanned
820 function proxyCheck() {
821 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
822 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
824 if ( !$wgBlockOpenProxies ) {
830 if ( $wgUseMemCached ) {
831 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
832 $mcValue = $wgMemc->get( $mcKey );
840 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
841 $iphash = md5( $wgIP . $wgProxyKey );
842 $url = $title->getFullURL( 'ip='.$iphash );
844 foreach ( $wgProxyPorts as $port ) {
845 $params = implode( ' ', array(
846 escapeshellarg( $wgProxyScriptPath ),
847 escapeshellarg( $wgIP ),
848 escapeshellarg( $port ),
849 escapeshellarg( $url )
851 exec( "php $params &>/dev/null &" );
854 if ( $wgUseMemCached ) {
855 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
864 function mergeChangesInto( &$text ){
865 $yourtext = $this->mArticle
->fetchRevisionText();
867 $db =& wfGetDB( DB_SLAVE
);
868 $oldText = $this->mArticle
->fetchRevisionText(
869 $db->timestamp( $this->edittime
),
872 if(wfMerge($oldText, $text, $yourtext, $result)){
881 function checkUnicodeCompliantBrowser() {
882 global $wgBrowserBlackList;
883 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
884 foreach ( $wgBrowserBlackList as $browser ) {
885 if ( preg_match($browser, $currentbrowser) ) {
893 * Format an anchor fragment as it would appear for a given section name
894 * @param string $text
898 function sectionAnchor( $text ) {
899 global $wgInputEncoding;
900 $headline = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
902 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
903 $headline = trim( $headline );
904 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
905 $replacearray = array(
910 array_keys( $replacearray ),
911 array_values( $replacearray ),
916 * Shows a bulletin board style toolbar for common editing functions.
917 * It can be disabled in the user preferences.
918 * The necessary JavaScript code can be found in style/wikibits.js.
920 function getEditToolbar() {
921 global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
924 * toolarray an array of arrays which each include the filename of
925 * the button image (without path), the opening tag, the closing tag,
926 * and optionally a sample text that is inserted between the two when no
927 * selection is highlighted.
928 * The tip text is shown when the user moves the mouse over the button.
930 * Already here are accesskeys (key), which are not used yet until someone
931 * can figure out a way to make them work in IE. However, we should make
932 * sure these keys are not defined on the edit page.
935 array( 'image'=>'button_bold.png',
938 'sample'=> wfMsg('bold_sample'),
939 'tip' => wfMsg('bold_tip'),
942 array( 'image'=>'button_italic.png',
945 'sample'=> wfMsg('italic_sample'),
946 'tip' => wfMsg('italic_tip'),
949 array( 'image'=>'button_link.png',
952 'sample'=> wfMsg('link_sample'),
953 'tip' => wfMsg('link_tip'),
956 array( 'image'=>'button_extlink.png',
959 'sample'=> wfMsg('extlink_sample'),
960 'tip' => wfMsg('extlink_tip'),
963 array( 'image'=>'button_headline.png',
966 'sample'=> wfMsg('headline_sample'),
967 'tip' => wfMsg('headline_tip'),
970 array( 'image'=>'button_image.png',
971 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
973 'sample'=> wfMsg('image_sample'),
974 'tip' => wfMsg('image_tip'),
977 array( 'image' =>'button_media.png',
978 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
980 'sample'=> wfMsg('media_sample'),
981 'tip' => wfMsg('media_tip'),
984 array( 'image' =>'button_math.png',
985 'open' => "\\<math\\>",
986 'close' => "\\</math\\>",
987 'sample'=> wfMsg('math_sample'),
988 'tip' => wfMsg('math_tip'),
991 array( 'image' =>'button_nowiki.png',
992 'open' => "\\<nowiki\\>",
993 'close' => "\\</nowiki\\>",
994 'sample'=> wfMsg('nowiki_sample'),
995 'tip' => wfMsg('nowiki_tip'),
998 array( 'image' =>'button_sig.png',
1002 'tip' => wfMsg('sig_tip'),
1005 array( 'image' =>'button_hr.png',
1006 'open' => "\\n----\\n",
1009 'tip' => wfMsg('hr_tip'),
1013 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1015 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1016 foreach($toolarray as $tool) {
1018 $image=$wgStylePath.'/common/images/'.$tool['image'];
1019 $open=$tool['open'];
1020 $close=$tool['close'];
1021 $sample = wfEscapeJsString( $tool['sample'] );
1023 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1024 // Older browsers show a "speedtip" type message only for ALT.
1025 // Ideally these should be different, realistically they
1026 // probably don't need to be.
1027 $tip = wfEscapeJsString( $tool['tip'] );
1029 #$key = $tool["key"];
1031 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1034 $toolbar.="addInfobox('" . wfEscapeJsString( wfMsg( "infobox" ) ) .
1035 "','" . wfEscapeJsString( wfMsg( "infobox_alert" ) ) . "');\n";
1036 $toolbar.="document.writeln(\"</div>\");\n";
1038 $toolbar.="/*]]>*/\n</script>";
1043 * Output preview text only. This can be sucked into the edit page
1044 * via JavaScript, and saves the server time rendering the skin as
1045 * well as theoretically being more robust on the client (doesn't
1046 * disturb the edit box's undo history, won't eat your text on
1049 * @todo This doesn't include category or interlanguage links.
1050 * Would need to enhance it a bit, maybe wrap them in XML
1051 * or something... that might also require more skin
1052 * initialization, so check whether that's a problem.
1054 function livePreview() {
1057 header( 'Content-type: text/xml' );
1058 header( 'Cache-control: no-cache' );
1060 echo $this->getPreviewText( false, false );
1065 * Get a diff between the current contents of the edit box and the
1066 * version of the page we're editing from.
1068 * If this is a section edit, we'll replace the section as for final
1069 * save and then make a comparison.
1071 * @return string HTML
1073 function getDiff() {
1074 require_once( 'DifferenceEngine.php' );
1075 $oldtext = $this->mArticle
->getContent( true );
1076 $newtext = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
1077 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1078 $oldtitle = wfMsg( 'currentrev' );
1079 $newtitle = wfMsg( 'yourtext' );
1080 if ( $oldtext != wfMsg( 'noarticletext' ) ||
$newtext != '' ) {
1081 $difftext = DifferenceEngine
::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
1084 return '<div id="wikiDiff">' . $difftext . '</div>';